home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pctqmd.pqs / PCTQMD.PAS
Pascal/Delphi Source File  |  1985-06-03  |  24KB  |  545 lines

  1. (*$V-,R-,B-*)
  2. Program PctQmd;
  3.  
  4. (* --------------------------------------------------------------------- *)
  5. (*                                                                       *)
  6. (*     Program:  PctQmd                                                  *)
  7. (*                                                                       *)
  8. (*     Purpose:  Converts PC-Talk phone directory to QMODEM phone        *)
  9. (*               directory.                                              *)
  10. (*                                                                       *)
  11. (*                                                                       *)
  12. (*     Usage:    Execute  'PCTQMD.COM'.                                  *)
  13. (*                                                                       *)
  14. (*               The PC-Talk phone directory file PC-TALK.DIR must be    *)
  15. (*               in the current DOS directory when this program is run.  *)
  16. (*                                                                       *)
  17. (*               The existence of the file PC-TALK.DIR is verified.  If  *)
  18. (*               it cannot be opened the program aborts.  Likewise, the  *)
  19. (*               program aborts if the file QMODEM.FON cannot be opened  *)
  20. (*               for output.                                             *)
  21. (*                                                                       *)
  22. (*               After verifying that the two directory files can be     *)
  23. (*               opened, prompts are issued for the default baud rate,   *)
  24. (*               parity, character size, and stop bits.  These data are  *)
  25. (*               used to construct a default QMODEM directory record to  *)
  26. (*               pad out any remaining unfilled records in the QMODEM    *)
  27. (*               directory.                                              *)
  28. (*                                                                       *)
  29. (*               I/O errors when reading or writing result in a program  *)
  30. (*               abort, and the QMODEM directory file is erased.         *)
  31. (*                                                                       *)
  32. (*               PC-Talk allows for Odd parity, but QMODEM currently     *)
  33. (*               does not.  Hence, all PC-Talk entries for Odd parity    *)
  34. (*               are changed to No parity.                               *)
  35. (*                                                                       *)
  36. (*     Remarks:  As an alternative to prompting for the default Qmodem   *)
  37. (*               parameters, those previously set for PC-Talk could be   *)
  38. (*               used.  Also, the dialing prefixes from some versions of *)
  39. (*               PC-Talk could be mapped to the corresponding QMODEM     *)
  40. (*               prefix numbers.                                         *)
  41. (*                                                                       *)
  42. (*     Author:   Philip R. Burns                                         *)
  43. (*               December 15, 1984                                       *)
  44. (*                                                                       *)
  45. (*     Note:     Comments and suggestions for changes are welcome.       *)
  46. (*               Leave a message on Gene Plantz's BBS at (312) 882 4145  *)
  47. (*               or Ron Fox's BBS at (312) 940 6494.                     *)
  48. (*                                                                       *)
  49. (* --------------------------------------------------------------------- *)
  50.  
  51. Const
  52.                                    (* QMODEM phone directory size  *)
  53.    Size_Of_Qmodem_File = 200;
  54.                                    (* Initial records to ignore in *)
  55.                                    (* PC-TALK.DIR                  *)
  56.    PcTalk_Ignore       = 4;
  57.  
  58. Type
  59.                                    (* To match any size string parameter *)
  60.    AnyStr = String[255];
  61.                                    (* Parity type in Qmodem *)
  62.    Check_Bit = ( None, Even );
  63.  
  64.                                    (* QMODEM phone directory file format *)
  65.    Qmodem_Record = Record
  66.                       Name:   String[25];
  67.                       Number: String[14];
  68.                       Speed:  Integer;
  69.                       Dbits:  Integer;
  70.                       Sbits:  Integer;
  71.                       Parity: Check_Bit;
  72.                    End;
  73.                                    (* PC-Talk phone directory file format *)
  74.  
  75.    PcTalk_Record = Record
  76.                       Name:    Array[ 1 .. 24 ] Of Char;
  77.                       Filler1: Array[ 1 .. 22 ] Of Char;
  78.                       Number:  Array[ 1 .. 14 ] Of Char;
  79.                       Filler2: Array[ 1 ..  2 ] Of Char;
  80.                       Speed:   Array[ 1 ..  4 ] Of Char;
  81.                       Parity:  Char;
  82.                       Dbits:   Char;
  83.                       Sbits:   Char;
  84.                       Filler3: Array[ 1 .. 59 ] Of Char;
  85.                    End;
  86.  
  87. Var
  88.                                    (* QMODEM phone directory file      *)
  89.    QmodemF :  File of Qmodem_Record;
  90.  
  91.                                    (* PC-Talk phone directory file     *)
  92.    PcTalkF :  File of PcTalk_Record;
  93.  
  94.                                    (* Entry for QMODEM directory file  *)
  95.    Qmodem_Entry : Qmodem_Record;
  96.                                    (* Default entry for QMODEM file    *)
  97.    Default_Qmodem_Entry: Qmodem_Record;
  98.                                    (* Entry for PC-Talk directory file *)
  99.    PcTalk_Entry: PcTalk_Record;
  100.                                    (* Number of PC-Talk entries        *)
  101.    PcTalk_Count: Integer;
  102.  
  103. (* --------------------------------------------------------------------- *)
  104. (*           TRIM --- Remove leading and trailing blanks from string     *)
  105. (* --------------------------------------------------------------------- *)
  106.  
  107. Function Trim( S: AnyStr ) : AnyStr;
  108.  
  109. (* --------------------------------------------------------------------- *)
  110. (*                                                                       *)
  111. (*     Function:   Trim                                                  *)
  112. (*                                                                       *)
  113. (*     Purpose:    Removes leading and trailing blanks from a string.    *)
  114. (*                                                                       *)
  115. (*     Calling Sequence:                                                 *)
  116. (*                                                                       *)
  117. (*        Trimmed_String := TRIM( S : Anystr ) : Anystr;                 *)
  118. (*                                                                       *)
  119. (*           S              --- String to be trimmed                     *)
  120. (*           Trimmed_String --- String after trimming                    *)
  121. (*                                                                       *)
  122. (*     Calls:  Copy, Length                                              *)
  123. (*                                                                       *)
  124. (*     Called By:  Transfer_Entries                                      *)
  125. (*                                                                       *)
  126. (* --------------------------------------------------------------------- *)
  127.  
  128. Var
  129.    I :  Integer;
  130.    J :  Integer;
  131.    L :  Integer;
  132.  
  133. Begin (* Trim *)
  134.  
  135.    L := LENGTH( S );
  136.    J := L;
  137.  
  138.    While ( J > 1 ) AND ( S[J] = ' ' ) Do
  139.       J := J - 1;
  140.  
  141.    I := 1;
  142.  
  143.    While ( I <= L ) AND ( S[I] = ' ' ) Do
  144.       I := I + 1;
  145.  
  146.  
  147.    Trim := Copy( S, I, J - I + 1 );
  148.  
  149. End   (* Trim *);
  150.  
  151. (* --------------------------------------------------------------------- *)
  152. (*           IO_Check --- Check for and Abort if IO error found          *)
  153. (* --------------------------------------------------------------------- *)
  154.  
  155. Procedure IO_Check( Message : AnyStr; Record_Number : Integer );
  156.  
  157. (* --------------------------------------------------------------------- *)
  158. (*                                                                       *)
  159. (*     Procedure:  IO_Check                                              *)
  160. (*                                                                       *)
  161. (*     Purpose:    Checks for and aborts in case of IO error             *)
  162. (*                                                                       *)
  163. (*     Calling Sequence:                                                 *)
  164. (*                                                                       *)
  165. (*        IO_Check( Message : AnyStr; Record_Number : Integer );         *)
  166. (*                                                                       *)
  167. (*           Message --- Message text to abort with if IO error found    *)
  168. (*           Record_Number --- Record in which IO error occurs           *)
  169. (*                                                                       *)
  170. (*     Calls:  IOResult, Halt                                            *)
  171. (*                                                                       *)
  172. (*     Called By:  PctQmd                                                *)
  173. (*                                                                       *)
  174. (* --------------------------------------------------------------------- *)
  175.  
  176. Begin (* IO_Check *);
  177.  
  178.    If IOResult <> 0 Then
  179.       Begin
  180.          Writeln( Message, ', record = ', Record_Number );
  181.          Erase( QmodemF );
  182.          Close( QmodemF );
  183.          Close( PcTalkF );
  184.          Halt;
  185.       End;
  186.  
  187. End   (* IO_Check *);
  188.  
  189. (* --------------------------------------------------------------------- *)
  190. (*           Open_Files --- Open PC-Talk and QMODEM directory files      *)
  191. (* --------------------------------------------------------------------- *)
  192.  
  193. Procedure Open_Files;
  194.  
  195. (* --------------------------------------------------------------------- *)
  196. (*                                                                       *)
  197. (*     Procedure:  Open_Files                                            *)
  198. (*                                                                       *)
  199. (*     Purpose:    Opens the PC-Talk and QMODEM directory files          *)
  200. (*                                                                       *)
  201. (*     Calling Sequence:                                                 *)
  202. (*                                                                       *)
  203. (*        Open_Files;                                                    *)
  204. (*                                                                       *)
  205. (*     Calls:  Assign, Reset, Rewrite, IOResult, Halt                    *)
  206. (*                                                                       *)
  207. (*     Called By:  PctQmd                                                *)
  208. (*                                                                       *)
  209. (* --------------------------------------------------------------------- *)
  210.  
  211. Var
  212.    YesNo  : Char;
  213.  
  214. Begin (* Open_Files *)
  215.                                    (* Verify that PC-TALK.DIR exists. *)
  216.                                    (* Abort if not found.             *)
  217.    Assign( PcTalkF , 'PC-TALK.DIR' );
  218.    (*$I-*)
  219.       Reset( PcTalkF );
  220.    (*$I+*)
  221.  
  222.    If IOResult <> 0 Then
  223.       Begin
  224.          Writeln(' Can''t open the PC-TALK.DIR file for input.');
  225.          Halt;
  226.       End;
  227.                                    (* Check if a QMODEM.FON file  *)
  228.                                    (* already exists.  If so, ask *)
  229.                                    (* if it should be trashed.    *)
  230.    Assign( QmodemF , 'QMODEM.FON' );
  231.    (*$I-*)
  232.       Reset( QmodemF );
  233.    (*$I+*)
  234.  
  235.    If IOResult = 0 Then
  236.       Begin
  237.  
  238.          Writeln('QMODEM dialing directory file QMODEM.FON already exists.');
  239.          Writeln('Continuing to run this program will overwrite it.       ');
  240.  
  241.          Repeat
  242.             Writeln;
  243.             Write  ('Do you want to continue (enter Y or N )? ');
  244.             Read( Kbd , YesNo );
  245.             Write( YesNo );
  246.          Until( YesNo In ['Y','y','N','n'] );
  247.  
  248.          If YesNo In ['N','n'] Then
  249.             Begin
  250.                Writeln;
  251.                Writeln('OK, this program will stop now.');
  252.                Close( PcTalkF );
  253.                Close( QmodemF );
  254.                Halt;
  255.             End
  256.          Else
  257.             Begin
  258.                Writeln;
  259.                Writeln('OK, this program will continue.');
  260.                Close( QmodemF );
  261.             End;
  262.  
  263.       End;
  264.                                    (* Open QMODEM.FON for output. *)
  265.                                    (* Verify QMODEM.FON opened.   *)
  266.                                    (* Abort if not.               *)
  267.    Assign( QmodemF , 'QMODEM.FON' );
  268.    (*$I-*)
  269.       Rewrite( QmodemF );
  270.    (*$I+*)
  271.  
  272.    If IOResult <> 0 Then
  273.       Begin
  274.          Writeln(' Can''t open the QMODEM.FON file for output.');
  275.          Close( PcTalkF );
  276.          Halt;
  277.       End;
  278.  
  279. End   (* Open_Files *);
  280.  
  281. (* --------------------------------------------------------------------- *)
  282. (*           Transfer_Entries --- Transfer PC-Talk to QMODEM entries     *)
  283. (* --------------------------------------------------------------------- *)
  284.  
  285. Procedure Transfer_Entries;
  286.  
  287. (* --------------------------------------------------------------------- *)
  288. (*                                                                       *)
  289. (*     Procedure:  Transfer_Entries                                      *)
  290. (*                                                                       *)
  291. (*     Purpose:    Transfer PC-Talk entries to QMODEM entries.           *)
  292. (*                                                                       *)
  293. (*     Calling Sequence:                                                 *)
  294. (*                                                                       *)
  295. (*        Transfer_Entries;                                              *)
  296. (*                                                                       *)
  297. (*     Calls:  IO_Check                                                  *)
  298. (*                                                                       *)
  299. (*     Called By:  PctQmd                                                *)
  300. (*                                                                       *)
  301. (* --------------------------------------------------------------------- *)
  302.  
  303. Var
  304.    Error_Code : Integer;
  305.    I          : Integer;
  306.  
  307. Begin (* Transfer_Entries *)
  308.                                    (* Zero count of PC-Talk entries read.*)
  309.                                    (* Different versions of PC-Talk      *)
  310.                                    (* have different size dialing        *)
  311.                                    (* directories.                       *)
  312.  
  313.    PcTalk_Count := 0;
  314.                                    (* Ignore first few records of the    *)
  315.                                    (* PcTalk directory file.             *)
  316.  
  317.    For I := 1 To PcTalk_Ignore Do
  318.       Begin
  319.                                    (* Read PC-Talk directory entry       *)
  320.          (*$I-*)
  321.          Read ( PcTalkF , PcTalk_Entry );
  322.          (*$I+*)
  323.  
  324.                                    (* Check if Read went OK              *)
  325.          IO_Check(' Error reading record from PC-Talk file', PcTalk_Count );
  326.  
  327.       End;
  328.  
  329.                                    (* Begin loop over PC-Talk entries.   *)
  330.                                    (* For each, transfer relevant data   *)
  331.                                    (* to corresponding entry in QMODEM   *)
  332.                                    (* phone directory file.              *)
  333.  
  334.    While ( NOT EOF( PcTalkF ) ) Do
  335.       Begin
  336.                                    (* Read PC-Talk directory entry       *)
  337.          (*$I-*)
  338.          Read ( PcTalkF , PcTalk_Entry );
  339.          (*$I+*)
  340.                                    (* Increment count of entries read    *)
  341.          PcTalk_Count := PcTalk_Count + 1;
  342.  
  343.                                    (* Check if Read went OK              *)
  344.          IO_Check(' Error reading record from PC-Talk file', PcTalk_Count );
  345.  
  346.                                    (* Transfer info to QMODEM entry      *)
  347.          Qmodem_Entry.Name   := PcTalk_Entry.Name + ' ';
  348.          Qmodem_Entry.Number := PcTalk_Entry.Number;
  349.  
  350.          VAL( TRIM( PcTalk_Entry.Speed ), Qmodem_Entry.Speed, Error_Code );
  351.          VAL(       PcTalk_Entry.Dbits  , Qmodem_Entry.Dbits, Error_Code );
  352.          VAL(       PcTalk_Entry.Sbits  , Qmodem_Entry.Sbits, Error_Code );
  353.  
  354.          Case PcTalk_Entry.Parity OF
  355.             'E': Qmodem_Entry.Parity := Even;
  356.             'O': Qmodem_Entry.Parity := None;
  357.             'N': Qmodem_Entry.Parity := None;
  358.             Else
  359.                  Qmodem_Entry.Parity := None;
  360.          End;
  361.  
  362.                                    (* Write out QMODEM entry             *)
  363.          (*$I-*)
  364.          Write( QmodemF , Qmodem_Entry );
  365.          (*$I+*)
  366.                                   (* Check if Write went OK              *)
  367.          IO_Check(' Error writing record to Qmodem file', PcTalk_Count );
  368.  
  369.       End;
  370.  
  371.    Writeln;
  372.    Writeln( PcTalk_Count, ' PC-Talk phone directory entries copied to Qmodem ',
  373.             'directory file QMODEM.FON.');
  374.    Writeln;
  375.    Delay( 2000 );
  376.  
  377. End    (* Transfer_Entries *);
  378.  
  379. (* --------------------------------------------------------------------- *)
  380. (*     Get_Default_Qmodem_Entry --- Read default QMODEM settings.        *)
  381. (* --------------------------------------------------------------------- *)
  382.  
  383. Procedure Get_Default_Qmodem_Entry;
  384.  
  385. (* --------------------------------------------------------------------- *)
  386. (*                                                                       *)
  387. (*     Procedure:  Get_Default_Qmodem_Entry                              *)
  388. (*                                                                       *)
  389. (*     Purpose:    Reads default QMODEM directory values for padding out *)
  390. (*                 QMODEM.FON file.                                      *)
  391. (*                                                                       *)
  392. (*     Calling Sequence:                                                 *)
  393. (*                                                                       *)
  394. (*        Get_Default_Qmodem_Entry;                                      *)
  395. (*                                                                       *)
  396. (*     Calls:  None                                                      *)
  397. (*                                                                       *)
  398. (*     Called By:  PctQmd                                                *)
  399. (*                                                                       *)
  400. (* --------------------------------------------------------------------- *)
  401.  
  402. Var
  403.    D_Char   : Char;
  404.    D_Speed  : Integer;
  405.    D_Dbits  : Integer;
  406.    D_Sbits  : Integer;
  407.    D_Parity : Check_Bit;
  408.    D_OK     : Boolean;
  409.    YesNo    : Char;
  410.  
  411. Begin (* Get_Default_Qmodem_Entry *)
  412.  
  413.    D_OK := FALSE;
  414.  
  415.    While ( NOT D_OK ) Do
  416.       Begin
  417.  
  418.          Repeat
  419.             Writeln;
  420.             Write('Enter choice for default baud rate:  1) 300   2) 1200: ');
  421.             Read( Kbd , D_Char );
  422.             Write( D_Char );
  423.          Until ( D_Char IN ['1', '2'] );
  424.  
  425.          If D_Char = '1' Then D_Speed := 300
  426.                          Else D_Speed := 1200;
  427.  
  428.          Repeat
  429.             Writeln;
  430.             Write('Enter choice for default number of data bits:  7 or 8: ');
  431.             Read( Kbd , D_Char );
  432.             Write( D_Char );
  433.          Until ( D_Char IN ['7','8'] );
  434.  
  435.          If D_Char = '7' Then D_Dbits := 7
  436.                          Else D_Dbits := 8;
  437.  
  438.          Repeat
  439.             Writeln;
  440.             Write('Enter choice for default number of stop bits:  1 or 2: ');
  441.             Read( Kbd , D_Char );
  442.             Write( D_Char );
  443.          Until ( D_Char IN ['1','2'] );
  444.  
  445.          If D_Char = '1' Then D_Sbits := 1
  446.                          Else D_Sbits := 2;
  447.  
  448.          Repeat
  449.             Writeln;
  450.             Write('Enter choice for default parity:  1) Even  2) None:    ');
  451.             Read( Kbd , D_Char );
  452.             Write( D_Char );
  453.          Until ( D_Char IN ['1','2'] );
  454.  
  455.          If D_Char = '1' Then D_Parity := Even
  456.                          Else D_Parity := None;
  457.  
  458.          Repeat
  459.             Writeln;
  460.             Write('Are these defaults OK? (Enter Y or N): ');
  461.             Read( Kbd , YesNo );
  462.             Write( YesNo );
  463.          Until ( YesNo IN ['Y','y','N','n'] );
  464.  
  465.          D_OK := ( YesNo IN ['Y','y'] );
  466.  
  467.    End (* While D_OK *);
  468.  
  469.    Writeln;
  470.  
  471.    With Default_Qmodem_Entry Do
  472.       Begin
  473.          Name   := '-------------------------';
  474.          Number := '- --- --- ----';
  475.          Speed  := D_Speed;
  476.          Dbits  := D_Dbits;
  477.          Sbits  := D_Sbits;
  478.          Parity := D_Parity;
  479.       End;
  480.  
  481. End    (* Get_Default_Qmodem_Entry *);
  482.  
  483. (* --------------------------------------------------------------------- *)
  484. (*     Pad_With_Default --- Pad out QMODEM file with default entries     *)
  485. (* --------------------------------------------------------------------- *)
  486.  
  487. Procedure Pad_With_Default;
  488.  
  489. (* --------------------------------------------------------------------- *)
  490. (*                                                                       *)
  491. (*     Procedure:  Pad_With_Default                                      *)
  492. (*                                                                       *)
  493. (*     Purpose:    Pads out QMODEM directory file with default (blank)   *)
  494. (*                 entries.                                              *)
  495. (*                                                                       *)
  496. (*     Calling Sequence:                                                 *)
  497. (*                                                                       *)
  498. (*        Pad_With_Default;                                              *)
  499. (*                                                                       *)
  500. (*     Calls:  IO_Check                                                  *)
  501. (*                                                                       *)
  502. (*     Called By:  PctQmd                                                *)
  503. (*                                                                       *)
  504. (* --------------------------------------------------------------------- *)
  505.  
  506. Var
  507.    I : Integer;
  508.  
  509. Begin (* Pad_With_Default *)
  510.  
  511.                                    (* Pad QMODEM directory file with the *)
  512.                                    (* default entry.                     *)
  513.  
  514.    For I := ( PcTalk_Count + 1 ) To Size_Of_Qmodem_File Do
  515.       Begin
  516.                                   (* Write out a default entry.          *)
  517.          Write( QmodemF , Default_Qmodem_Entry );
  518.  
  519.                                   (* Check if Write went OK              *)
  520.          IO_Check(' Error writing record to QMODEM file', I );
  521.  
  522.       End;
  523.  
  524. End    (* Pad_With_Default *);
  525.  
  526. (* --------------------------------------------------------------------- *)
  527. (*                     PctQmd --- Main Program                           *)
  528. (* --------------------------------------------------------------------- *)
  529.  
  530. Begin (* PctQmd *)
  531.                                    (* Open PC-Talk, QMODEM directories.  *)
  532.    Open_Files;
  533.                                    (* Obtain default QMODEM entry.       *)
  534.    Get_Default_Qmodem_Entry;
  535.                                    (* Transfer PC-Talk entries to QMODEM.*)
  536.    Transfer_Entries;
  537.                                    (* Pad QMODEM directory file with the *)
  538.                                    (* default entry.                     *)
  539.    Pad_With_Default;
  540.  
  541.                                    (* Close files and exit normally.     *)
  542.    Close( QmodemF );
  543.    Close( PcTalkF );
  544.  
  545. End   (* PctQmd *).